import request from "@/utils/request";
// import { File } from "@/api/file";

const AUTH_BASE_URL = "/api/auth";

const AuthAPI = {
  // '查询是否签署协议'
  hasSigned(data: ReqhasSigned) {
    return request<any, ReshasSigned>({
      url: `${AUTH_BASE_URL}/userAgree/queryUserAgree`,
      method: "post",
      headers: {
        Authorization: "no-auth",
      },
      data,
    });
  },
  //签署协议接口....
  signAgreement(data: ReqsignAgreement) {
    return request<any, string>({
      url: `${AUTH_BASE_URL}/userAgree/addUserAgree`,
      method: "post",
      headers: {
        Authorization: "no-auth",
      },
      data,
    });
  },
  // 用户登录接口
  userLogin(data: RequserLogin) {
    return request<any, ResuserLogin>({
      url: `${AUTH_BASE_URL}/user/phone/reg`,
      method: "post",
      headers: {
        Authorization: "no-auth",
      },
      data,
    });
  },
  //获取验证码
  getVerificationCode(data: ReqgetVerificationCode) {
    return request({
      url: `${AUTH_BASE_URL}/user/sendSms`,
      method: "post",
      data,
      headers: {
        Authorization: "no-auth",
      },
    });
  },

  /** 登录接口*/
  // login(data: LoginFormData) {
  //   const formData = new FormData();
  //   formData.append("account", data.account);
  //   formData.append("password", data.password);
  //   formData.append("userType", data.userType);
  //   return request<any, LoginResult>({
  //     url: `${AUTH_BASE_URL}/user/login`,
  //     method: "post",
  //     data: formData,
  //     headers: {
  //       "Content-Type": "application/json",
  //     },
  //   });
  // },

  /** 刷新 token 接口*/
  refreshToken(refreshToken: string) {
    return request<any, LoginResult>({
      url: `${AUTH_BASE_URL}/user/refresh-token`,
      method: "post",
      params: { refreshToken: refreshToken },
      headers: {
        Authorization: "no-auth",
      },
    });
  },

  /** 注销登录接口 */
  logout() {
    return request({
      url: `${AUTH_BASE_URL}/user/logout`,
      method: "delete",
    });
  },

  /** 获取验证码接口*/
  getCaptcha() {
    return request<any, CaptchaInfo>({
      url: `${AUTH_BASE_URL}/user/captcha`,
      method: "get",
    });
  },
  // 获取地区数据
  getAreaList() {
    return request<any, any>({
      url: `${AUTH_BASE_URL}/area/tree`,
      method: "get",
    });
  },
  // 申请成为主播
  submitApply(data: RegisterBaseInfo) {
    return request<any, any>({
      url: `api/anchor/info/apply`,
      method: "post",
      data,
    });
  },
  // 获取用户信息
  getUserInfo(data: { userBizId: string }) {
    return request<any, any>({
      url: `api/anchor/info/show?userBizId=${data.userBizId}`,
      method: "get",
      // data,
    });
  },

  // 获取保证金支付二维码
  getPayCode(data: { payType: string; userBizId: string }) {
    return request<any, any>({
      url: `api/anchor/info/pay`,
      method: "post",
      data,
    });
  },
  // 获取支付结果
  getPayResult(data: { outTradeNo: string }) {
    return request<any, any>({
      url: `/api/fms/aggPay/getOrderPayInfoFree`,
      method: "post",
      data,
    });
  },
  // 获取合同模板
  getContract(category: number) {
    return request<any, any>({
      url: `/api/official/contract/get/${category}`,
      method: "get",
    });
  },
};

export default AuthAPI;

export interface ReqgetVerificationCode {
  //验证码数据类型
  phone: string;
  type: string;
  areaCode: string;
  clientType?: string;
}

export interface RequserLogin {
  // 登录接口数据
  phoneNumber: string;
  captcha: string;
  clientType?: string;
}

export interface ResuserLogin {
  //登录响应
  httpMsg?: string;
  msg?: string;
  loginTime: number;
  token: string;
  userType: any;
  anchor: any;
  permissions: any;
  roles: any;
  isSuperAdmin: any;
  userBizId: any;
  imUserId: any;
}
export interface ReqsignAgreement {
  //签署协议接口数据
  isStandard: string;
  isAgreement: string;
  userAccount: string;
}
// export interface RessignAgreement {
//   //签署协议接口返回
//   isStandard: string;
//   isAgreement: string;
//   userAccount: string;
// }
export interface ReqhasSigned {
  //协议查询接口数据
  userAccount: string;
}
export interface ReshasSigned {
  isStandard: string;
  isAgreement: string;
}
/** 登录表单数据 */
export interface LoginFormData {
  /** 用户名 */
  account: string;
  /** 密码 */
  password: string;
  /** 用户类型：1官方端 2公会端 3主播端 */
  userType: string;
}

/** 登录响应 */
export interface LoginResult {
  /** 访问令牌 */
  accessToken: string;
  /** 刷新令牌 */
  refreshToken: string;
  /** 令牌类型 */
  tokenType: string;
  /** 过期时间(秒) */
  expiresIn: number;
}

/** 验证码信息 */
export interface CaptchaInfo {
  /** 验证码缓存key */
  captchaKey: string;
  /** 验证码图片Base64字符串 */
  captchaBase64: string;
}

// 注册表单基础信息
export interface RegisterBaseInfo {
  name: string; // 姓名
  age: number | string; // 年龄
  idCardType: number | string; // 证件类型：1身份证
  papers: string; // 证件号
  province: string; // 省
  city: string; // 市
  district: string; // 区
  category: number | string; // 主播类别：1交友相亲 2情感互动 3悦耳声优 4搞笑娱乐 5游戏陪玩 6哄睡剧场
  bankNo: number | string; // 银行卡号
  bank: string; // 开户行
  bankScanUrl: string; // 银行卡扫描件
  bankFrontUrl: string; // 银行卡正面
  bankReverseUrl: string | Array<string>; // 银行卡反面
  area?: Array<string>;
}

// 提交材料信息
export interface RegisterAuthInfo {
  idCardFrontUrl: string; // 身份证正面
  idCardReverseUrl: string; // 身份证反面
  videoUrl: string | Array<string>; // 手持身份证录制视频
  pactScanUrl: string | Array<string>; // 合同扫描件
  gameDanUrl: string; // 游戏段位图片
  recUrl: string | Array<string>; // 录音文件
  masUrl: string | Array<string>; // 视频文件
}

export type SubmitInfo = RegisterBaseInfo &
  RegisterAuthInfo & {
    userBizId: string; // 主播唯一ID(必填)
    regStatus: number; // 注册进度：1填写基础信息 2上传认证资料 3等待审核 4缴纳保证金 5注册成功（必填）
    videoDemoUrl: string;
    gameDanDemoUrl: string;
  };
